package com.sx.pipeline.ui.task.postpone

import android.view.View
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.loper7.date_time_picker.DateTimeConfig
import com.loper7.date_time_picker.dialog.CardDatePickerDialog
import com.sx.pipeline.BR
import com.sx.pipeline.R
import com.sx.pipeline.app.base.CYDataBindingBaseActivity
import com.sx.pipeline.app.config.IntentKey
import com.sx.pipeline.arouth.RoutePath
import com.sx.pipeline.databinding.ActPostponeTasksBinding
import com.sx.pipeline.ui.task.ReleaseTaskVM
import com.sx.pipeline.utils.AndroidUtil


/**
 * @Author: YY
 * @Date: 2022/4/5
 * @Description: 我的发布-任务详情-延期任务
 */
@Route(path = RoutePath.Mine.TASK_POSTPONE)
class PostPoneTaskActivity :
    CYDataBindingBaseActivity<ActPostponeTasksBinding, ReleaseTaskVM>(R.layout.act_postpone_tasks),
    View.OnClickListener {
    @JvmField
    @Autowired(name = IntentKey.ID)
    var taskId: Int? = 0

    private var time=""

    override fun initData() {
        super.initData()
        mBinding.setVariable(BR.onClick, this)
        mBinding.titleBar.leftView.setOnClickListener {
            finish()
        }
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.tv_task_time->{
                CardDatePickerDialog.builder(this)
                    .setTouchHideable(true)
                    .showBackNow(false)
                    .setMinTime(System.currentTimeMillis())
                    .showFocusDateInfo(false)
                    .setWrapSelectorWheel(false)
                    .setTitle("选择修改时间")
                    .showDateLabel(true)
                    .setBackGroundModel(CardDatePickerDialog.STACK)
                    .setDisplayType(
                        DateTimeConfig.YEAR,
                        DateTimeConfig.MONTH,
                        DateTimeConfig.DAY,
                        DateTimeConfig.HOUR,
                        DateTimeConfig.MIN,
                        DateTimeConfig.SECOND
                    )
                    .setLabelText("年", "月")
                    .setOnChoose("选择") {
                        time=AndroidUtil.conversionTime(it, "yyyy-MM-dd HH:mm:ss")
                        mBinding.tvTaskTime.text =
                            AndroidUtil.conversionTime(it, "yyyy-MM-dd HH:mm:ss")
                    }
                    .setOnCancel("关闭") {

                    }
                    .build().show()
            }
            R.id.tv_submit -> {
                //提交申请延期
                taskId?.let { mViewModel.getTaskDelay(it,time,mBinding.etReason.text.toString()) }
            }
        }
    }

}